import { createRouter, createWebHistory } from 'vue-router'
import { useStore } from '../store'
import index from "../pages/Index.vue"
import { storeToRefs } from 'pinia'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      component: () => import('../pages/Index.vue')
    },
    {
      path: '/index',
      component: () => import('../pages/Index.vue')
    },
    {
      path: '/fenlei1/:id',
      name: "fenlei1",
      component: () => import('../pages/Fengleiye.vue')
    }, {
      path: '/gouwuche',
      component: () => import('../pages/Gouwuche.vue')
    },
    {
      path: "/Home",
      component: () => import("../pages/Home.vue")
    },
    {
      path: "/shouhuo/Tianjia/",
      component: () => import("../pages/shouhuo/Tianjia.vue")
    },
    {
      path:"/shangpin",
      component:()=> import("../pages/Shangpinxiangqing.vue")
    },
    {
      path: "/Home-aa/",
      component: () => import("../pages/dingdan/Dingdan.vue"),
      children: [
        {
          path: '',
          component: () => import("../pages/dingdan/Fukuan.vue")
        },
        {
          path: 'a',
          component: () => import("../pages/dingdan/Fukuan.vue")
        },
        {
          path: "b",
          component: () => import("../pages/dingdan/Peisong.vue")
        },
        {
          path: "c",
          component: () => import("../pages/dingdan/Jieshou.vue"),
        },
        {
          path: "d",
          component: () => import("../pages/dingdan/Wancheng.vue")
        }
      ]
    },
    {
      path: "/login",
      component: () => import("../pages/Denglu.vue")
    }
  ],
})
router.beforeEach((to,from)=>{
  let store=useStore()
  let arr=['/gouwuche',"/Home","/Home-aa/"]
  if(arr.includes(to.path)){
    // let token=localStorage.getItem("token");
    if(!store.token){
      return {path:"/login"}
    }
  }
})
export default router
